import { NestFactory } from '@nestjs/core';
import { AdminModule } from './admin.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';
import * as session from 'express-session';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AdminModule);
  app.enableCors({
    origin: true,
    credentials: true,
  });
  app.useStaticAssets('static/uploads', {
    prefix: '/uploads',
  });
  app.use(
    session({
      secret: process.env.SECRET,
      resave: false,
      saveUninitialized: false,
    }),
  );
  const options = new DocumentBuilder()
    .setTitle('网上书城-后台API')
    .setDescription('使用nestjs+mongodb制作的一个后台接口')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api-docs', app, document);

  await app.listen(process.env.ADMIN_PORT);
}
bootstrap();
